package com.caption.api.handler.impl;
import com.caption.api.entity.IDCarAuthCondition;
import com.caption.api.entity.IDCarAuthResultDTO;
import com.caption.api.handler.base.AbstractHandler;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * 身份认证处理类
 */
public class IDCardAuthHandler extends AbstractHandler {
    private IDCarAuthCondition condition;

    public IDCardAuthHandler(IDCarAuthCondition condition){
        this.condition=condition;
    }

    /**
     * 多线成并发请求
     * @return
     * @throws ExecutionException
     * @throws InterruptedException
     * @throws TimeoutException
     */
    @Override
    public IDCarAuthResultDTO call() throws ExecutionException, InterruptedException, TimeoutException {
       Future<IDCarAuthResultDTO> future = this.getApiSupport().getCommonExecutor().submit(()->{
           IDCarAuthResultDTO idCarAuthResultDTO = this.getApiSupport().getIdCardAuthClient().call(condition).getData();
           return idCarAuthResultDTO;
        });
        return future.get(120, TimeUnit.SECONDS);
    }
}
